USE ProjectAASP_KFC
GO

Create proc insertUser
(
	@Name nvarchar(50),
	@Pass nvarchar(50),
	@Email varchar(50),
	@Address nvarchar(100),
	@Phone nvarchar(12)
)
AS
BEGIN
	INSERT INTO [User](Name,Pass,Email,[Address],Phone) VALUES (@Name,@Pass,@Email,@Address,@Phone)
	
END
GO

Create proc insertOrder
(
	@UserID int,
	@PromotionID int,
	@Address nvarchar(150),
	@Phone nvarchar(11) ,
	@EmployeeID int ,
	--@OrderDate datetime ,
	@Comment nvarchar(200),
	@Confirmed bit ,
	@Finished bit ,
	@MoneySum float,
	@OrderID int output
)
AS
BEGIN
	INSERT INTO [Order](UserID,PromotionID,[Address],Phone,EmployeeID,OrderDate,Comment,Confirmed,Finished,MoneySum)
	VALUES (@UserID,@PromotionID,@Address,@Phone,@EmployeeID,GETDATE(),@Comment,@Confirmed,@Finished,@MoneySum)
	
	SET @OrderID = 
	(
		SELECT OrderID
		FROM [Order]
		WHERE UserID = @UserID
			AND Comment = @Comment
			AND MoneySum = @MoneySum
	)
END
GO

Create proc insertOrderDetails
(
	@OrderID int,
	@FoodID int,
	@Number int,
	@PromotionPercent int
)
AS
BEGIN
	INSERT INTO OrderDetails(OrderID,FoodID,Number,PromotionPercent)
	VALUES (@OrderID,@FoodID,@Number,@PromotionPercent)
END
GO
